<template>
	<view style="margin-left: 30px;margin-right: 30px">
		<button @click="notworkdown()"> 下载图片</button>
		<button @click="notworkdownvoid()"> 下载视频</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				imageURL: ''
			}
		},
		methods: {
		    notworkdown() {
		      this.downloadTask = wx.downloadFile({
		        url: 'https://cdn.pixabay.com/photo/2025/11/05/20/57/monastery-9939590_1280.jpg', 
		        success: (res) => {
		          if (res.statusCode === 200) {
		            this.imageURL = res.tempFilePath;
		          }
		        },
		        fail: (err) => {
		          console.error('下载失败：', err);
		        }
		      });
		      this.downloadTask.onProgressUpdate((res) => {
		        this.progress = res.progress; 
		        this.written = res.totalBytesWritten; 
		        this.expected = res.totalBytesExpectedToWrite; 
		        console.log('下载进度：', res.progress + '%');
		        console.log('已下载：', res.totalBytesWritten, 'B');
		        console.log('总大小：', res.totalBytesExpectedToWrite, 'B');
		      });
		    },
			notworkdownvoid() {
			  this.downloadTask = wx.downloadFile({
			    url: 'https://media.w3.org/2010/05/sintel/trailer.mp4', 
			    success: (res) => {
			      if (res.statusCode === 200) {
			        this.imageURL = res.tempFilePath;
			      }
			    },
			    fail: (err) => {
			      console.error('下载失败：', err);
			    }
			  });
			  this.downloadTask.onProgressUpdate((res) => {
			    this.progress = res.progress; 
			    this.written = res.totalBytesWritten; 
			    this.expected = res.totalBytesExpectedToWrite; 
			    console.log('下载进度：', res.progress + '%');
			    console.log('已下载：', res.totalBytesWritten, 'B');
			    console.log('总大小：', res.totalBytesExpectedToWrite, 'B');
			  });
			},
		  },
		  }
</script>

<style>

</style>